package com.xjgc.share;

import com.thoughtworks.xstream.annotations.XStreamOmitField;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * 中间库共享产线分页VO
 *
 * @author: 小逗号
 * @date: 2023-10-10
 * @description:
 * @since:
 */
@Data
@NoArgsConstructor
public class ShareVo<T> {
    /**
     * 源业务系统请求流水号
     */
    @NotNull
    @XStreamOmitField
    private String serialNo;

    /**
     * 总包号
     */
    private Long pageTotal;
    /**
     * 分包号
     */
    private Long pageNo;

    private Boolean finish;

    private List<T> dataList;

    private Integer size;
    private Long total;

    public ShareVo(ShareParam param, Long size, List<T> dataList) {
        this.serialNo = param.getSerialNo();
        this.pageNo = param.getPageNo();
        this.total = size;
        this.dataList = dataList;
        this.size = dataList.size();

        BigDecimal pageSize = new BigDecimal(param.getPageSize());
        BigDecimal dataSize = new BigDecimal(size);
        BigDecimal divide = dataSize.divide(pageSize, 0, BigDecimal.ROUND_UP);
        this.pageTotal = divide.longValue();
        this.finish = this.size == 0 || this.pageTotal == 0 || this.pageNo.equals(this.pageTotal);
    }
}
